{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4cb1e807",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'ZiQi', 'stu1802': 'XiaoFeng', 'stu1803': 'LiuYu'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = {\n",
    "     \"stu1801\":\"ZiQi\",\n",
    "     \"stu1802\":\"XiaoFeng\",\n",
    "     \"stu1803\":\"LiuYu\"\n",
    " }\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4d593575",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1801\n",
      "stu1802\n",
      "stu1803\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历一个字典 \n",
    "for i in info:\n",
    "    print(i)   #i在字典里面是key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b96d9a86",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1801 ZiQi\n",
      "stu1802 XiaoFeng\n",
      "stu1803 LiuYu\n"
     ]
    }
   ],
   "source": [
    "#循环遍历整个字典的 items\n",
    "for k,v in info.items():\n",
    "    print(k,v)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d0cd9082",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'1801': 'ZiQi'}\n",
      "{'1801': 'ZiQi', '1802': 'XiaoFeng'}\n",
      "{'1801': 'ZiQi', '1802': 'XiaoFeng', '1803': 'LiuYu'}\n"
     ]
    }
   ],
   "source": [
    "#实践1：目标:stu1801中取出数字，作为新的字典key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "#用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v\n",
    "    print(new_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0413fe4d",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "#实践2： value变成大写\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "#用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v.upper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d4ea00b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#实践3：让new_info key由'1801'>1801"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
